<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class M_master_jenis_abhp extends CI_Model {

	public function __construct() {
		parent::__construct();
	}

	function get() {
		$sql = 'SELECT * FROM master_jenis_abhp';
		return $sql;
	}

	function cek($rule) {
		$sql = 'SELECT * FROM master_jenis_abhp WHERE jenis_abhp=? OR kd_jenis_abhp=?';
		$query = $this->db->query($sql, $rule);
        return $query;
	}

	function cekUpdate($rule) {
		$sql = 'SELECT * FROM master_jenis_abhp WHERE (jenis_abhp=? OR kd_jenis_abhp=?) AND kd_jenis_abhp<>?';
		$query = $this->db->query($sql, $rule);
        return $query;
	}

	function get_cari($keyword='') {
		$sql = 'SELECT * FROM master_jenis_abhp WHERE jenis_abhp like "%'.$keyword.'%" OR kd_jenis_abhp like "%'.$keyword.'%"';
		return $sql;
	}

	function get_export() {
		$sql = 'SELECT * FROM master_jenis_abhp';
		$query = $this->db->query($sql);
		if ($query->num_rows() > 0) {
			$result = $query->result_array();
			$query->free_result();
		} else {
			$result = array();
		}
		return $result;
	}

	function get_ket($params) {
		$sql = 'SELECT ket FROM master_jenis_abhp WHERE kd_jenis_abhp = ? AND id_produksi = ?';
		$query = $this->db->query($sql, $params);
		if ($query->num_rows() > 0) {
			$result = $query->row_array();
			$query->free_result();
		} else {
			$result = array();
		}
		return $result['ket'];
	}

	function save($dataInsert) {
		$query = $this->db->insert('master_jenis_abhp', $dataInsert);
		return $query;
	}

	function get_by($params) {
		$sql = 'SELECT * FROM master_jenis_abhp WHERE kd_jenis_abhp = ?';
		$query = $this->db->query($sql, $params);
		if ($query->num_rows() > 0) {
			$result = $query->row_array();
			$query->free_result();
		} else {
			$result = array();
		}
		return $result;
	}

	function update($kd_jenis_abhp, $dataUpdate) {
		$this->db->where('kd_jenis_abhp', $kd_jenis_abhp);
		$update = $this->db->update('master_jenis_abhp', $dataUpdate);
		return $update;
	}

	function delete($kd_jenis_abhp) {
		$this->db->where('kd_jenis_abhp', $kd_jenis_abhp);
		$delete = $this->db->delete('master_jenis_abhp');
		return $delete;
	}
}
